<template>
  <page-header-wrapper :title="false">
    <a-card title="专利类型标签管理" style="width: 600px">
      <template slot="extra">
        <a-button size="small" type="primary" icon="plus" @click="onAdd">添加</a-button>
      </template>
      <a-tag v-for="item in tagList" :key="item.id" closable @close="(e) => delTag(e, item.id)">{{item.title}}</a-tag>
    </a-card>
    <a-modal
      title="添加标签"
      v-model="setVisible"
      :width="400"
      @ok="onSubmit"
    >
      <a-form-model
        ref="setForm"
        :model="setForm"
      >
        <a-form-model-item label="标签名称">
          <a-input type="text" v-model="setForm.title" placeholder="标签名称，用于设置专利业务所属类型的" />
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </page-header-wrapper>
</template>

<script>
import { addLabel, delLabel, getLabel } from '@/api/patent.process'
export default {
  name: 'TagList',
  data () {
    return {
      setVisible: false,
      tagList: [],
      setForm: {}
    }
  },
  created () {
    this.getTag()
  },
  methods: {
    getTag () {
      const app = this
      getLabel().then(res => {
        app.tagList = res.result.data
      })
    },
    onAdd () {
      this.setForm = {}
      this.setVisible = true
    },
    delTag (e, id) {
      delLabel(id).then(res => {
        this.getTag()
      })
    },
    onSubmit () {
      const app = this
      app.$refs.setForm.validate(valid => {
        if (valid) {
          addLabel(app.setForm).then(res => {
            app.setVisible = false
            app.getTag()
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
